#ifndef IMAGESHARED_H
#define IMAGESHARED_H
#include<QPixmap>
#include"myecpoint.h"
#include<openssl/ec.h>
#include<QTableWidget>
enum SaveMethod{
    LSB=0,
    EMD=1,
    TXT=2,
    IMA=3,
    NON=-1
};
class imageShared
{
    friend class MainWindow;
    friend class imageRecover;
public:
    imageShared(std::shared_ptr<EC_GROUP> group);

    QImage recover(const QVector<QByteArrayList>& ans,const QString& pubInfoFileName,int setR,void(*logFun)(QString)=nullptr);
    QImage recover(const QVector<QByteArrayList>& ans, const QJsonObject& obj, int setR);
    bool setImage(QString fileName);
    QVector<unsigned int> getRofSet(unsigned int setCount); //得到每个授权集合的标识
    QString getPubInfo(const QVector<QByteArrayList>& shadows,const QVector<unsigned int>& setR,const QVector<QStringList>&  set);
    bool    savePubInfo(QString savePos,QString json);
    QVector<QByteArrayList> getShadow(unsigned int participatorCount,int L=128);
    bool saveShadow(const QVector<QByteArrayList>& shadow, const QString& savePos, const QTableWidget& cyz, SaveMethod method=TXT,QString carImagePos="");
    bool saveShadowToImage(const QByteArrayList& shadow,const QString& savePos,const QTableWidget& cyz);
    bool saveShadowToTxt(const QByteArrayList& shadow,const QString& savePos,const QTableWidget& cyz);
    bool saveShadowToLSB(const QByteArrayList& shadow, const QString& savePos, const QTableWidget& cyz, const QString &image);
    bool saveShadowToEMD(const QByteArrayList& shadow,const QString& savePos,const QTableWidget& cyz, const QString &image);
private:
    std::shared_ptr<EC_GROUP> m_group=nullptr;//椭圆曲线
    MyECPoint m_point;    //椭圆曲线基点
    QImage m_image{};     //要共享的图像
    int participatorCount;//参与者数量
    int m_k;              //每个子秘密有多少像素
    int m_aSelectBits;    //p=m*depth+r，aSelectBits=m*depth每个子秘密有多少位
    int m_L;              //一个秘密组的秘密个数
    int m_N;              //把图像按L个子秘密为一组分组，组数为m_N
private:
    bool getSystemParameters(int L);
    QByteArray getSubSelect(const uchar* data,int dataLen,int subLen,int pos);
    QByteArrayList getShadow(const QVector<QByteArrayList>& shadow);
    QByteArrayList splitImage();
};

#endif // IMAGESHARED_H
//1100101000101
//1100111001101
